home *** CD-ROM | disk | FTP | other *** search
Text File | 1990-04-30 | 3.6 KB | 111 lines | [TEXT/MPS ] |
- {[j=20/53/1$] Pasmat Options}
-
- {-------------------------------------------------------------------------------------------}
- {----------------------------------TRectStack Methods---------------------------------------}
- {-------------------------------------------------------------------------------------------}
- {$S AOpen}
-
- PROCEDURE TRectStack.IRectStack(initialNumberOfRects: Integer);
-
- { Calls IDynamicArray with “initialNumberOfRects” and an element size of SizeOf(Rect). This
- will allocate enough memory in the heap to store at least an “initialNumberOfRects” of
- Rects without taking any Memory Manager hit.}
-
- BEGIN
- SELF.IDynamicArray(initialNumberOfRects, SizeOf(Rect));
- END;
-
- {-------------------------------------------------------------------------------------------}
- {$S ARes}
-
- PROCEDURE TRectStack.ClearStack;
-
- { Removes all the items from the stack. }
-
- BEGIN
- SELF.DeleteElementsAt(1, GetSize);
- END;
-
- {-------------------------------------------------------------------------------------------}
- {$S ARes}
-
- PROCEDURE TRectStack.EachRect(PROCEDURE DoToRect(theRect: Rect); direction: Boolean);
-
- { Calls the passed DoToRect procedure for each item on the stack. It traverses the stack in
- ‘direction’ order. If ‘direction’ is kForward, then we start with the first element pushed
- onto the stack, and proceed to the last (most recent) element on the stack. }
-
- VAR
- dummy: ArrayIndex;
-
- FUNCTION DoToItem(elementIndex: ArrayIndex): Boolean;
-
- VAR
- theRect: Rect;
-
- BEGIN
-
- { Get the rectangle that is associated with this index number, and pass it off
- to the procedure that was passed in to us: DoTorect. }
-
- SELF.GetElementsAt(elementIndex, @theRect, 1);
- DoToRect(theRect);
-
- { The core iterating routine of TDynamicArray - EachElementDoTil - is designed
- to iterate until a certain condition is true. This condition is defined by
- the PROCEDURE parameter that is passed to it. EachElementDoTil just keeps
- iterating until that procedure returns TRUE (or until we run out of
- elements). Since we want EachRect to iterate over ALL items on the stack, we
- always return FALSE. }
-
- DoToItem := FALSE;
- END;
-
- BEGIN
-
- { We iterate over the stack by calling the generic EachElementDoTil method of
- TDynamicArray. For each element in the stack, our DoToItem procedure will be
- called with the index of the item that needs to be processed. Our DoToItem
- procedure uses this index to get the corresponding Rect, which it in turns
- passes to the DoToRect procedure that was passed to us. }
-
- dummy := SELF.EachElementDoTil(DoToItem, direction);
- END;
-
- {-------------------------------------------------------------------------------------------}
- {$S ARes}
-
- PROCEDURE TRectStack.PushRect(theRect: Rect);
-
- { Takes the Rect you pass it, and pushes it on the stack. It does this by inserting the item
- after the last item in the array. We know how large the array is with the
- TDynamicArray.GetSize method. }
-
- BEGIN
- SELF.InsertElementsBefore(GetSize + 1, @theRect, 1);
- END;
-
- {-------------------------------------------------------------------------------------------}
- {$S ARes}
-
- PROCEDURE TRectStack.PopRect(VAR theRect: Rect);
-
- { Returns the first Rect on the stack. That Rect is then removed from the stack. }
-
- BEGIN
- SELF.GetElementsAt(GetSize, @theRect, 1);
- SELF.DeleteElementsAt(GetSize, 1);
- END;
-
- {-------------------------------------------------------------------------------------------}
- {$S AFields}
-
- PROCEDURE TRectStack.Fields(PROCEDURE DoToField(fieldName: Str255; fieldAddr: Ptr;
- fieldType: Integer)); OVERRIDE;
-
- BEGIN
- DoToField('TRectStack', NIL, bClass);
-
- INHERITED Fields(DoToField);
- END;
-